/*
 * @Author: LBH 1336709799@qq.com
 * @Date: 2024-10-28 12:20:29
 * @LastEditors: LBH 1336709799@qq.com
 * @LastEditTime: 2024-11-02 09:36:14
 * @FilePath: \enjoy_plus_three\lib\pages\home\index.dart
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */

import 'package:enjoy_plus_three/pages/home/components/home_list.dart';
import 'package:enjoy_plus_three/pages/home/components/home_nav.dart';
import 'package:enjoy_plus_three/stores/counter.dart';
import 'package:enjoy_plus_three/utils/http.dart';
import 'package:enjoy_plus_three/utils/toast.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class HomePage extends StatefulWidget {
  const HomePage({super.key});

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  @override
  void initState() {
    getNotifyList();
    super.initState();
  }

  List notifyList = [];

  getNotifyList() async{
    try{
      final res = await http.get('/announcement');
      if(res['code'] != 10000) return ToastUtil.showError('获取数据失败');
      ToastUtil.showSuccess('获取数据成功');
      setState(() {
        notifyList = res['data'];
      });
    }catch(e){
      ToastUtil.showError('获取数据失败');
    }
  }

  @override
  Widget build(BuildContext context) {
    final counter = Provider.of<Counter>(context);
    return Scaffold(
      backgroundColor: const Color.fromARGB(40, 85, 145, 175),
      appBar: AppBar(
        title: Text('享+社区${counter.count}'),
        backgroundColor: Colors.transparent,
        centerTitle: true,
      ),
      body: ListView(
        scrollDirection: Axis.vertical,
        padding: const EdgeInsets.all(10),
        children:  [
          // 导航条
          HomeNav(),
          // 中间广告图
          ClipRRect(
            borderRadius: BorderRadius.circular(10.0),
            child: Image.asset('images/banner@2x.jpg'),
          ),
          // 社区公告
           HomeList(notifyList:notifyList)
        ],
      )
    );
  }
}